package dal;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
	
	public static void main(String argv[]) {
		int port = 22222;
        while(true){
                
        		ServerSocket serverSocket;
				try {
					serverSocket = new ServerSocket(port);
					Socket socket = serverSocket.accept();
					Thread thread = new Thread(socket);
					System.out.println("Client Connected");
					thread.run();
					
					serverSocket.close();
				} catch (IOException e) {
					System.out.println("SHICE");
					e.printStackTrace();
				}
        }
        
	}
    
	public String schreibeNachricht(java.net.Socket socket, String cmd) throws IOException { // You run this from the main
	    PrintWriter pw = new PrintWriter(socket.getOutputStream(), true);
	    pw.println(cmd);
	    pw.flush();
	    pw.close();
	    return null;
	}
	
	public String leseNachricht(java.net.Socket socket) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		String got = br.readLine();
		br.close();
		return got;
	}
}
